const path = require("path");
const ejs = require("ejs");

function compileEjs(tempName, data) {
  return new Promise((resolve, reject) => {
    const tempPath = `../template/${tempName}`;
    const absolutionPath = path.resolve(__dirname, tempPath);

    ejs.renderFile(absolutionPath, data, (err, result) => {
      if (err) {
        console.log("编译买吧失败", err);
        reject(err);
        return;
      }

      console.log(result);
      resolve(result);
    });
  });
}

module.exports = {
  compileEjs,
};
